/*
 *  SVMGestureClassifier.cpp
 *  
 *
 *  Created by Rasmus Kyng on 14/02/2011.
 *  Copyright 2011 __MyCompanyName__. All rights reserved.
 *
 */
#include "HandInterface.hpp"
using namespace hi;
using namespace cv;

SVMGestureClassifier::SVMGestureClassifier(  const char* mlName, string pcaName, cv::Ptr< AbstractProbabilityTransformer > probTransPtr )
: MLGestureClassifier( pcaName, probTransPtr ) {
	// -- ML load/prepare -- //
	svm = CvSVM();
	char* svmFileName_orphan = strAppend_orphanOut( mlName, ".svm.xml" ); //TODO handle via resource tracker
	svm.load( svmFileName_orphan, mlName );
	delete svmFileName_orphan;
}

bool SVMGestureClassifier::predict( cv::Mat& dataSampleForPrediction ) {
	float gesturePrediction = svm.predict( dataSampleForPrediction );
	
	bool predictedActive;
	
	if ( gesturePrediction == 0.0) {
		predictedActive = true;
		//circle(imgToDraw, Point(20, 5), 4, Scalar(0, 0, 255), 2); //FIX add existence check!
	} else if ( gesturePrediction == 1.0) {
		predictedActive = false;
		//circle(imgToDraw, Point(20, 5), 2, Scalar(0, 255, 0), 2);
	} else {
		CV_Error( CV_StsError, "Unexpected prediction!"); //throws exception!
	}
	
	return predictedActive;
}